package com.lovo.test.MapText;

import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

public class Text {
    public  static HashMap<Integer,String> map = new HashMap<Integer, String>();
    public static void main(String[] args) {
        map.put(1, "Amy");
        map.put(2, "Joe");
        map.put(3, "Tom");
        map.put(4, "Susan");
        traverse();
        insert();
        delete();
        modify();
    }

    //修改信息
    public static void modify() {
        map.replace(3, "Tommy");
        traverse();
    }

    //删除信息
    public static void delete(){
        map.remove(4);
    }

    //插入信息
    public static void insert(){
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入要插入的名字");
        String name = scan.next();
        map.put(5, name);
    }

    //遍历信息
    public static void traverse(){
        Set set = map.keySet();
        for (Object obj:set) {
            System.out.println(obj+":"+map.get(obj));
        }
    }
}
